package com.example.pcackage;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * @Auther: LIJingQi
 * @Description: 配置类
 * @Date: 2023/3/30 23:18
 */
@Configuration
@ComponentScan(basePackages = "com.example")
//开启事务的注解
@EnableTransactionManagement
public class JavaConfig {
    @Bean
    DataSource dataSource(){
        DriverManagerDataSource ds=new DriverManagerDataSource();
        ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
        ds.setUsername("root");
        ds.setPassword("Lumli");
        ds.setUrl("jdbc:mysql://127.0.0.1:3306/sscm?serverTimezone=UTC");
        return  ds;
    }
    @Bean
    JdbcTemplate jdbcTemplate(){
        return new JdbcTemplate(dataSource());
    }
    @Bean
    PlatformTransactionManager platformTransactionManager(){
        return  new DataSourceTransactionManager(dataSource());
    }
}
